// pages/restaurant/moveDinnerCar/moveDinnerCar.js
import {
  nlist
} from '../../../api/shop';
import util from '../../../utils/util'
const app=getApp()
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  lifetimes: {
    attached() {
      var _this = this
      //获取经纬度
      wx.getLocation({
        type: 'gcj02',
        isHighAccuracy:true,
        success(res) {
          _this.data.latitude = res.latitude
          _this.data.longitude = res.longitude
          _this.loadCar()
          _this.setData({
            latitude: _this.data.latitude,
            longitude: _this.data.longitude
          })

        },
        fail: err => {}
      })
    
    }
  },
  /**
   * 组件的初始数据
   */
  data: {
    markers: [],
    latitude: '',
    cars:[],
    shop:{},
    longitude: ''
  },

  /**
   * 组件的方法列表
   */
  methods: {
    bindmarker(e){
     this.data.cars.forEach(item=>{
     
        if(e.detail.markerId==item.id){
            this.data.shop=item
        }
     })
     
      this.setData({
        shop:this.data.shop
      })
    },

    callouttap(){
      wx.navigateTo({
        url: '/pages/shop/shopDetail/index?shopId='+this.data.shop.id+'&mchId='+this.data.shop.mchId
      })  
    },
    loadCar() {
      nlist({
        scopeType: 4,
        lng:this.data.longitude,
        lat:this.data.latitude,
        pageNumber: 100
      }).then(res => {
          res.data.data.forEach(item=>{
            item.distance=util.rateConverter(item.distance)
            var mark={
              latitude:item.lat,
              longitude:item.lng,
              id:item.id,
              width:'15',
              height:'20',
              customCallout:{
                display:'BYCLICK'
              },
              iconPath:'http://rzico.oss-cn-shenzhen.aliyuncs.com/dinnerBar/canyin/canyin-canchedingwei.png'
            }
            this.data.markers.push(mark)
            this.data.cars.push(item)
          })
          this.setData({
            cars:this.data.cars,
            markers:this.data.markers
          })
      })

    },
  }
})